package com.springboot.sakila;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.springboot.sakila.entity.Address;
import com.springboot.sakila.mapper.AddressMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import javax.annotation.Resource;

;

/*
 *DATE:2025/7/14
 */
@SpringBootTest
@Slf4j
public class AddressMapperTeat {
    @Resource
    private AddressMapper addressMapper;
    @Test
    public void testSelectById(){
        Address address = addressMapper.selectById(1);
        log.info("address: {}" + address);
    }
    @Test
    public void testInsertOne(){
        Address address = new Address(null, "aaa",
                "bbb", "ccc", 1, "42399",
                "716571220373", "POINT(175.2833399 -37.7833313)", null);
        addressMapper.insertOne(address);
    }
    @Test
    public void testUpdateOne(){
        Address address = new Address(611, "xxx",
                "bbb", "ccc", 1, "42399",
                "716571220373", "POINT(175.2833399 -37.7833313)", null);
        addressMapper.updateOne(address);
    }

    @Test
    public void testDeleteById(){
        addressMapper.deleteById(613);
    }

    @Test
    public void testSelectPage(){
        Page<Address> page = new Page<>(1, 5);
        OrderItem orderItem = new OrderItem();
        page.addOrder(orderItem.desc("address_id"));
        Page<Address> addressPage = addressMapper.selectPage("a", "", page);
        log.info("total: {}", addressPage.getTotal());
        log.info("pages: {}", addressPage.getPages());
        log.info("currentPage: {}", addressPage.getCurrent());
        log.info("size: {}", addressPage.getSize());
        log.info("records: {}", addressPage.getRecords());
    }

    @Test
    public void testSelectAAndCAndtForPages(){
        Page<Address> page = new Page<>(1, 5);
        OrderItem orderItem = new OrderItem();
        page.addOrder(orderItem.desc("address_id"));
        Page<Address> addressPage = addressMapper.selectAAndCAndtForPages("a", "", page);
        log.info("total: {}", addressPage.getTotal());
        log.info("pages: {}", addressPage.getPages());
        log.info("currentPage: {}", addressPage.getCurrent());
        addressPage.getRecords().forEach(address -> log.info("city-country: {}",
                address.getCity().getCity()+"-"+address.getCity().getCountry().getCountry()));
    }
}
